var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require("path");
var webpack = require("webpack");

// var extractCSS = new ExtractTextPlugin('[name].css');
// var extractSCSS = new ExtractTextPlugin('[name]1.css');

module.exports = {
  entry: './src/js/index.js',
  output: {
    path: 'testapi/public/',
    filename: '[hash:8].index_bundle.js',//增加hash
    hash: true,
    //publicPath:"dist",
    chunkFilename:"[name].min.js"
  },
  module:{
  	loaders:[
  		{ 
  			test:/\.jsx?$/,loader:"babel",exclude:/node_modules/,
  			query:
		      {
		        presets:["es2015", "stage-0", "react"]
		      }
  		},
  		{	//引入sass
  			test:/\.scss/,
  			loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader"),
  			exclude:/node_modules/
  		},
      { //引入less
        test:/\.less/,
        loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
      },
      { //引入css
        test:/\.css/,
        //loaders: ["style","css"]
        loader: ExtractTextPlugin.extract("style-loader", "css-loader")
      }
  	]
  },
  externals: {
	  'react': 'React',
	  'react-dom': 'ReactDOM',
    'react-router':'ReactRouter'
  },
  plugins: [//生成html
    new HtmlWebpackPlugin({
      title: 's1',
      filename:'index.html',
      template: 'src/assets/tpl/index.html'
    }),
    new ExtractTextPlugin("[name]123.css")
    // ,
    // //压缩用
    //  new webpack.optimize.UglifyJsPlugin({
    //    compressor:{
    //      warnings:false
    //    }
    //  })
  ]
  ,
  resolve: {
        alias: {
            echarts$: "echarts/src/echarts.js",
            echarts: "echarts/src",
            zrender$: "zrender/src/zrender.js",
            zrender: "zrender/src",
            ReactEcharts: path.join(__dirname, "src") + "/js/components/EchartsTcsl"
        }
  },
  babel: {
    plugins: [['import', {
      libraryName: 'antd',
      libraryDirectory: "lib",
      style: 'css',
    }]]
  }
};